from os.path import *
from random import *
from sys import *

bigfile = argv[1]
dir = argv[2]
infile = open(bigfile, "rb")#, 1)
outfile_path = join(dir, basename(bigfile))
print "writing to", outfile_path
outfile = open(outfile_path, "w+b", 0)
chkdata = ""
while True:
    buf = infile.read(randint(1, 0x20000))
    print "readed", len(buf), "bytes"
    if not buf:
        break
    outfile.write(buf)
    chkdata += buf
    outfile.seek(0)
    assert chkdata == outfile.read()
